package com.mocha.bss.domain.org.feign;

import com.coffee.core.CoffeeResponse;
import com.mocha.bss.domain.org.service.AdmdivService;
import com.mocha.bss.BssServerInfo;
import com.mocha.bss.org.api.AdmdivFeignService;
import com.mocha.bss.org.bo.PathBO;
import com.mocha.bss.org.vo.AdmdivVO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: songkui
 * @since 2025/03/24
 **/
@RestController
@AllArgsConstructor
@RequestMapping(BssServerInfo.ADMDIV_PATH)
public class AdmdivFeignServiceImpl implements AdmdivFeignService {

    private final AdmdivService admdivService;

    @Override
    @GetMapping("/list/{id}")
    public CoffeeResponse<List<AdmdivVO>> listById(@PathVariable("id") Long id) {
        return CoffeeResponse.responseSuccess(admdivService.listById(id));
    }

    @Override
    @GetMapping("/list/parent/{parentId}")
    public CoffeeResponse<List<AdmdivVO>> listByParentId(@PathVariable("parentId") Long parentId) {
        return CoffeeResponse.responseSuccess(admdivService.listByParentId(parentId));
    }

    @Override
    @PostMapping("/list-in-path")
    public CoffeeResponse<List<AdmdivVO>> listInPath(@RequestBody PathBO bo) {
        return CoffeeResponse.responseSuccess(admdivService.listInPath(bo.getPaths()));
    }

    @Override
    @PostMapping("/filter")
    public CoffeeResponse<List<AdmdivVO>> filter(@RequestBody PathBO bo) {
        return CoffeeResponse.responseSuccess(admdivService.filter(bo.getPaths()));
    }

    @Override
    @PostMapping("/paths")
    public CoffeeResponse<String[]> paths(PathBO bo) {
        String[] paths = bo.getPaths();
        if (paths == null || paths.length == 0) return CoffeeResponse.responseSuccess(admdivService.getPaths());
        return CoffeeResponse.responseSuccess(paths);
    }

}
